<?
session_start();
session_cache_limiter('private');
session_cache_expire(60*12);


include("../webkit/include/simple_db.php");

$db = new SimpleDB();
$action = $_GET["action"];
$callback = $_GET["callback"];
$json = "";

if($action == "check") {
	$sql = "select truename, user_status from jx_user where username='".$_GET["uid"]."' and userpass='".$_GET["pwd"]."'";
	$rec = $db->getOneRecord($sql);
	if($rec != null ) {
		if($rec['user_status'] == -1) {
			$json = "{'result' : 'sorry'}";
		} else {
			$_SESSION["uid"] = $_GET["uid"];
			$_SESSION["truename"] = $rec['truename'];
			if($_GET["uid"] == 'admin') {
				$_SESSION["user_flag"] = 'admin';
			}
			$db->query("update jx_user set login_count=login_count+1, last_login=now() where username='".$_GET["uid"]."'");
			$json = "{'result' : 'ok'}";
		}
	} else {
		$json = "{'result' : 'sorry'}";
	}
	echo $callback."(".$json.")";
}
else if($action == "logout") {
	unset($_SESSION["uid"]);
	unset($_SESSION["truename"]);
	unset($_SESSION["user_flag"]);
	header("location:login.html");
} 
?>